﻿
using Xacml.Core;
using System.Xml;

namespace Xacml.Core.Policy
{
  public class EnvironmentAttributeDesignatorElement : AttributeDesignatorBase
  {
    public override bool IsReadOnly
    {
      get
      {
        return false;
      }
    }

    public EnvironmentAttributeDesignatorElement(XmlReader reader, XacmlVersion version)
      : base(reader, version)
    {
    }

    public EnvironmentAttributeDesignatorElement(string dataType, bool mustBePresent, string attributeId, string issuer, XacmlVersion version)
      : base(dataType, mustBePresent, attributeId, issuer, version)
    {
    }

    public override void WriteDocument(XmlWriter writer)
    {
      writer.WriteStartElement("EnvironmentAttributeDesignator");
      writer.WriteAttributeString("AttributeId", this.AttributeId);
      writer.WriteAttributeString("DataType", this.DataType);
      if (!this.Issuer.Equals(string.Empty))
        writer.WriteAttributeString("Issuer", this.Issuer);
      if (this.MustBePresent)
        writer.WriteAttributeString("MustBePresent", "true");
      else
        writer.WriteAttributeString("MustBePresent", "false");
      writer.WriteEndElement();
    }
  }
}
